home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / patch / pagestream / pgs32tu3 / scripts.lha / MailMerge.rexx < prev    next >
OS/2 REXX Batch file  |  1996-11-04  |  4KB  |  140 lines

  1. /* $VER: MailMerge.rexx 1.1a (11.04.96)
  2.    Copyright 1996 SoftLogik Publishing Corporation
  3.    May not be distributed without SoftLogik Publishing Corporation's express written permission */
  4.  
  5. /* Data Format
  6.  
  7. field1name»field2name»field3name...
  8. record1field1»record1field2»record1field3...
  9. record2field1»record2field2»record2field3...
  10. ...
  11.  
  12. where » is a tab
  13.  
  14. Data Example:
  15.  
  16. Address    City    Name    State    ZipCode
  17. 315 Consort Drive    St. Louis    Joe User    MO    63011
  18. 7178 Sonoma Way    Los Angeles    Helen Hudson    CA    95011
  19. 1234 Howe St.    Vancouver    Fred Stone    BC    V9N 5N1
  20.  
  21. */
  22.  
  23. OPTIONS RESULTS
  24. TRACE OFF
  25.  
  26. /* Make sure rexx support is opened */
  27. IF ~SHOW('L','rexxsupport.library') THEN
  28.    CALL ADDLIB('rexxsupport.library',0,-30)
  29.  
  30. ADDRESS 'PAGESTREAM'
  31.  
  32. /* OPEN THE DATA FILE */
  33. getfile title "'Select the ASCII data file'" LOAD POSBUTTON "OK" NEGBUTTON "Cancel"
  34. if rc~=0 then signal cleanup
  35. dfile=result
  36. call open(.ifile, dfile, 'R')
  37.  
  38. /* READ AND PARSE THE HEADER */
  39. dheader=readln(.ifile)
  40. fcount=1
  41. do forever
  42.     tpos=pos(d2c(9),dheader)
  43.     if tpos=0 then field.fcount=dheader
  44.         else field.fcount=left(dheader,tpos-1)
  45.     if tpos=0 then break
  46.     dheader=right(dheader,length(dheader)-tpos)
  47.     fcount=fcount+1
  48. end
  49.  
  50. /* SEE IF THE VARIABLES ALREADY EXIST */
  51. "setvariablevalue <nul>" variable field.1
  52. if rc~=0 then call createvar()
  53.  
  54. /* MAIL MERGE */
  55. /* ASK USER IF OK TO PRINT */
  56. allocarexxrequester '"Mail Merge"' 352 89
  57.     hDialog=result
  58. addarexxgadget hDialog EXIT 12 70 70 label "Print"
  59.     hDialog.ok=result
  60. addarexxgadget hDialog EXIT 270 70 70 label "Cancel"
  61.     hDialog.cancel=result
  62. addarexxgadget hDialog TEXT 12 10 336 border none string "'Enter the number of copies and then click'"
  63. addarexxgadget hDialog TEXT 12 22 336 border none string "'on Print to start printing.'"
  64. addarexxgadget hDialog STRING 64 42 70 label "C_opies" string '1'
  65.     hCopies=result
  66. doarexxrequester hDialog
  67.     action=result
  68. getarexxgadget hDialog hCopies string
  69.     copies=result
  70. freearexxrequester hDialog
  71. if action=hDialog.cancel then signal cleanup
  72.  
  73. do forever
  74.     /* READ THE RECORD */
  75.     dline=readln(.ifile)
  76.     if dline="" then break
  77.  
  78.     /* PARSE THE RECORD */
  79.     do i=1 to fcount
  80.         tpos=pos(d2c(9),dline)
  81.         if tpos=0 then line.i=dline
  82.             else line.i=left(dline,tpos-1)
  83.         if pos(d2c(39),line.i)>0 then line.i=d2c(34)||line.i||d2c(34) /* thanks Warren! */
  84.             else line.i=d2c(39)||line.i||d2c(39)
  85.         dline=right(dline,length(dline)-tpos)
  86.         if tpos=0 then break
  87.     end i
  88.  
  89.     /* UPDATE PGS3 VARIABLES */
  90.     'refresh off' /* Thanks Michael Tanzer! */
  91.     do i=1 to fcount
  92.         "setvariablevalue "line.i variable field.i
  93.     end i
  94.  
  95.     'refreshon'
  96.     'refreshwindow'
  97.     'printdocument copies 'copies' page 1 sides both scale actual output grayscale printermarks off mirror off negative off'
  98. end
  99.  
  100. /* RESET VARIABLE NAMES */
  101. 'refresh on'
  102. do i=1 to fcount
  103.     "setvariablevalue <"field.i">" variable field.i
  104. end i
  105. 'refreshon'
  106. 'refreshwindow'
  107.  
  108. call cleanup()
  109. EXIT
  110.  
  111. CREATEVAR:
  112.     do i=1 to fcount
  113.         'newvariable 'field.i' «'field.i'»'
  114.     end i
  115.     /* 'newvariable +Next «+»'
  116.         We'll use this when Find/Replace is done for a Next Record control
  117.         The script will search the text for these. If found, it will have to
  118.         replace following variable uses until the next Next control with
  119.         varname.1, etc. Then the script will have to reset multiple var groups
  120.         at once. */
  121.  
  122.     /* INFORM USER THAT VARS ARE CREATED */
  123.     allocarexxrequester '"Mail Merge"' 364 105
  124.         hDialog=result
  125.     addarexxgadget hDialog EXIT 282 88 70 label "OK"
  126.         hDialog.ok=result
  127.     addarexxgadget hDialog TEXT 8 10 356 border none string "'The mail merge variables have been created.'"
  128.     addarexxgadget hDialog TEXT 8 22 356 border none string "'Use the Type/Insert Variable » User String'"
  129.     addarexxgadget hDialog TEXT 8 34 356 border none string "'command to insert them into your document.'"
  130.     addarexxgadget hDialog TEXT 8 46 356 border none string "'When you are done, save it and then choose'"
  131.     addarexxgadget hDialog TEXT 8 58 356 border none string "'this macro again to print it.'"
  132.     doarexxrequester hDialog
  133.     freearexxrequester hDialog
  134.     signal cleanup
  135. RETURN
  136.  
  137. CLEANUP:
  138. call close(.ifile)
  139. EXIT
  140.